package com.java.schedule.springbatch.process;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.java.schedule.springbatch.entity.EmployeeFrom;
import com.java.schedule.springbatch.entity.EmployeeDTO;
import com.java.schedule.springbatch.entity.EmployeeTo;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.stereotype.Component;

import java.util.Random;

@Component
public class EmployeeProcessor implements ItemProcessor<EmployeeDTO, EmployeeTo> {

    @Override
    public EmployeeTo process(EmployeeDTO employeeDTO) throws Exception {
        EmployeeTo employee = new EmployeeTo();
        employee.setEmployeeId(IdWorker.getId());
        employee.setFirstName(employeeDTO.getFirstName());
        employee.setLastName(employeeDTO.getLastName());
        employee.setEmail(employeeDTO.getEmail());
        employee.setAge(employeeDTO.getAge());
        // 抛出异常时，job被终止，如果不想job被终止，那么需要对异常的数据做处理
//        if(employeeDTO.getEmployeeId() > 1000L){
//            throw new RuntimeException("id大于1000，停止");
//        }
        System.out.println("inside processor " + employee.toString());
        return employee;
    }
}
